#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct edge
{
    int pos1;
    int pos2;
    int val;
};
struct CompareEdge {
    bool operator()(const edge& a, const edge& b) {
        return a.val > b.val;
    };
};
int findanc(vector<int>&st,int pos)
{
    while (st[pos] >= 0)
    {
        pos = st[pos];
    }
    return pos;
}
int main()
{
    int n;
    cin >> n;
    vector<int> st1(n+1, -1);
    priority_queue < edge, vector<edge>, CompareEdge > q;
    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        int m;
        cin >> m;
        while (m--)
        {
            int pos, val;
            cin >> pos >> val;
            int pos1 = findanc(st1, i), pos2 = findanc(st1, pos);
            if (pos1 != pos2)
            {
                st1[pos1] = pos2;
                count++;
            }
            q.push({ i,pos1,val });
        }
    }
    if (count != n - 1)
    {
        cout << "disjoint" << endl;
    }
    else
    {
        vector<int> st2(n+1, -1);
        int totalval = 0, num = 0;
        edge e = q.top();
        cout << e.pos1 << " ";
        while (num != n - 1)
        {
            edge ed = q.top();
            q.pop();
            int pp1 = findanc(st2, ed.pos1), pp2 = findanc(st2, ed.pos2);
            int val = ed.val;
            if (pp1 != pp2);
            {
                st2[pp1] = pp2;
                num++;
                totalval += val;
            }
        }
        cout << totalval << endl;
    }
    return 0;
}